﻿using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Charades_Word_Checker
{
	class Program
	{
		static void Main(string[] args)
		{
			var swGood = new StreamWriter(new FileStream("../../good.txt", FileMode.Append)) { AutoFlush = true };
			var swShit = new StreamWriter(new FileStream("../../shit.txt", FileMode.Append)) { AutoFlush = true };
			var qAll = new Queue<string>();

			Console.Title = "Charades Word Selector";
			Console.WriteLine("Helol");
			Console.Write("Loading all.txt...");
			try
			{
				using (var srAll = new StreamReader("../../all.txt"))
				{
					string tmp;
					while ((tmp = srAll.ReadLine()) != null)
					{
						qAll.Enqueue(tmp);
					}
				}
				Console.WriteLine("OK");
			}
			catch (Exception ex)
			{
				Console.WriteLine("Failed");
				Console.WriteLine(ex.Message);
				Console.WriteLine("Press any key to exit...");
				Console.ReadKey();
				Environment.Exit(0);
			}

			Console.Write("\nPress ");
			Console.ForegroundColor = ConsoleColor.Yellow;
			Console.Write("X");
			Console.ForegroundColor = ConsoleColor.Gray;
			Console.WriteLine(" to exit\n");

			while (qAll.Count > 0)
			{
				string curWord = qAll.Dequeue();
				Console.Write(curWord);
				switch ((Console.ReadKey()).Key)
				{
					case ConsoleKey.LeftArrow:
						Console.ForegroundColor = ConsoleColor.Red;
						Console.WriteLine("SHIT");
						swShit.WriteLine(curWord);
						break;
					case ConsoleKey.RightArrow:
						Console.ForegroundColor = ConsoleColor.Green;
						Console.WriteLine("OK");
						swGood.WriteLine(curWord);
						break;
					case ConsoleKey.X:
						qAll.Enqueue(curWord);
						var allFile = new FileInfo("../../all.txt");
						swGood.Close();
						swShit.Close();
						allFile.Delete();
						var swTmp = allFile.CreateText();
						while (qAll.Count > 0)
						{
							swTmp.WriteLine(qAll.Dequeue());
						}
						swTmp.Flush();
						swTmp.Close();
						Environment.Exit(0);
						break;
				}
				Console.ForegroundColor = ConsoleColor.Gray;
			}

		}
	}
}
